<?php

/**
 * This is the model class for table "{{bus_detail}}".
 *
 * The followings are the available columns in table '{{bus_detail}}':
 * @property integer $bus_detail_id
 * @property integer $direction
 * @property string $start_point
 * @property string $end_point
 * @property integer $start_time
 * @property integer $end_time
 * @property integer $bus_id
 * @property string $polyline
 */
class BusDetail extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return BusDetail the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{bus_detail}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
//			array('direction, start_point, end_point, start_time, end_time, bus_id, polyline', 'required'),
			array('direction, start_time, end_time, bus_id', 'numerical', 'integerOnly'=>true),
			array('start_point, end_point', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('bus_detail_id, direction, start_point, end_point, start_time, end_time, bus_id, polyline', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    'bus' => array(self::BELONGS_TO, 'Bus', 'bus_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'bus_detail_id' => 'Bus Detail',
			'direction' => 'Direction',
			'start_point' => 'Start Point',
			'end_point' => 'End Point',
			'start_time' => 'Start Time',
			'end_time' => 'End Time',
			'bus_id' => 'Bus',
			'polyline' => 'Polyline',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
                $criteria->with = array('bus');

		$criteria->compare('bus_detail_id',$this->bus_detail_id);
		$criteria->compare('direction',$this->direction);
		$criteria->compare('start_point',$this->start_point,true);
		$criteria->compare('end_point',$this->end_point,true);
		$criteria->compare('start_time',$this->start_time);
		$criteria->compare('end_time',$this->end_time);
		$criteria->compare('bus_id',$this->bus_id);
		$criteria->compare('polyline',$this->polyline,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}